package com.zikao.config;

import com.zikao.config.interceptor.UserInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Author: Likaisheng
 * @Description:
 * @Date: Created in 16:06:04 2021-02-10
 * @Modified By:
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {

    /**
     * Filter、Interceptor几乎拥有相同的功能，具体用哪个比较好？
     * 1、Filter是Servlet定义的原生组件。好处，脱离Spring应用也能使用
     * 2、Interceptor是Spring定义的接口。可以使用Spring的自动装配等功能
     */

    @Bean
    public UserInterceptor getLoginInterceptor(){
        return new UserInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/bootstrap/**","/images/**");
        super.addInterceptors(registry);
    }
}
